# -*- coding: utf-8 -*-
from datetime import timedelta
from airflow.operators.bash import BashOperator
from jms_hi.dm.dm_sham_send_monitor_sum_dt_update import jms_hi_dm__dm_sham_send_monitor_sum_dt_update
from airflow.exceptions import AirflowSkipException
import pendulum

cst = pendulum.timezone('Asia/Shanghai')

class HiBashOperator(BashOperator):
    def pre_execute(self, context):
        day = cst.convert(context['ti'].execution_date) + timedelta(days=1)

        days_of_hours = ['09','11','13','15','17']

        if day.strftime('%H') not in days_of_hours:
            print(f'{day.strftime("%H")} not in {days_of_hours}, should skip')
            raise AirflowSkipException()
        else:
            print(f'{day.strftime("%H")} in {days_of_hours}, run now')
            super().pre_execute(context)

jms_oracle__dm_sham_send_monitor_sum_dt_update= HiBashOperator(
    task_id='jms_oracle__dm_sham_send_monitor_sum_dt_update',
    execution_timeout=timedelta(hours=1),
    email=['yl_etl@yl-scm.com','suning@jtexpress-scm.com'],
    bash_command="jms_hi/oracle/dm_sham_send_monitor_sum_dt_update/execute.sh",
    pool='spmi_apack',
    retries=1,
    pool_slots=1,
)

jms_oracle__dm_sham_send_monitor_sum_dt_update << [jms_hi_dm__dm_sham_send_monitor_sum_dt_update]